package com.chenshu.aop_annotation.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-04-02
 * Time：16:59
 */
@Component
@Aspect
public class SubwayAspect {
    @Pointcut(value = "execution(* com.chenshu.aop_annotation.service.SubwayService.takeSubway())")
    private void myPointcut() {}

    @Before("myPointcut()")
    public void securityCheckAdvice() {
        System.out.println("前置通知：开始安全检查");
    }

    @After("myPointcut()")
    public void recordAdvice() {
        System.out.println("后置通知：记录本次行程");
    }

    @AfterThrowing("myPointcut()")
    public void expressionAdvice() {
        System.out.println("异常通知：运行过程出现异常");
    }

    @Around("myPointcut()")
    public void swipeAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕通知start：开始并刷卡进站");
        joinPoint.proceed();
        System.out.println("环绕通知finish：结束并刷卡出站");
    }

    @AfterReturning("myPointcut()")
    public void arriveDestination() {
        System.out.println("返回后通知：到达目的地");
    }
}
